<?php
/*
 * Created on Jan 24, 2010
 * Shopping Cart System
 * Owner: Phu Ha
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

Class Registry Implements ArrayAccess {
	private $vars = array();
	private $logger;
	
	function __construct() {
		$this->logger = Logger::getLogger(LOGGER_MVC);
		$this->logger->info('Initiate Registry object');
	}

	function set($key, $var) {
        if (isset($this->vars[$key]) == true) {
			$this->logger->info('Method set: Unable to set $key and $value, variable exists');
			throw new Exception('Unable to set var `' . $key . '`. Already set.');
        }
        $this->vars[$key] = $var;
        return true;
	}

	function get($key) {
        if (isset($this->vars[$key]) == false) {
			$this->logger->info('Method get: Unable to get $value, $key doesn\'t exist');
			return null;
        }
        return $this->vars[$key];
	}

	function remove($var) {
		unset($this->vars[$key]);
	}

	function offsetExists($offset) {
		return isset($this->vars[$offset]);
	}

	function offsetGet($offset) {
		return $this->get($offset);
	}

	function offsetSet($offset, $value) {
		$this->set($offset, $value);
	}

	function offsetUnset($offset) {
		unset($this->vars[$offset]);
	}
}

?>
